package Servlet;





import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;

@WebServlet("/dididi123")
public class ServletDemo02 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//       获取姓名
        String username = req.getParameter("username");
        System.out.println(username);
//        获取爱好
        String[] hobbies = req.getParameterValues("hobby");
        System.out.println(Arrays.toString(hobbies));
//          获取所有键值的map集合
        Map<String, String[]> map = req.getParameterMap();
//        遍历
        Set<String> strings = map.keySet();
        for (String key:strings) {
            String[] arr = map.get(key);
            System.out.println(key+":"+Arrays.toString(arr));
        }
    }
}
